<template>
  <div :class="{'block-wrap': true, reverse}">
    <div class="aside">
      <img/>
      <p class="name">{{data.name}}</p>
      <div class="btn-group">
        <span @click="joinGuarantee">加入担保</span>
        <span @click="toCompany">公司详情</span>
        <span @click="newDiscount">最新优惠</span>
      </div>
    </div>
    <div class="main">
      <div class="top">
        <div class="block guarantee">
          <div class="limit">
            <p>担保赔付额度：</p>
            <p>
              <span>{{compensationAmount.amount}}</span>
              {{compensationAmount.suffix}}
            </p>
          </div>
          <div class="user">
            <p>担保用户数：</p>
            <p>
              <span>{{data.userCount}}</span>
              人
            </p>
          </div>
        </div>
        <div class="block company">
          <div class="left">
            <p>成立时间：{{data.establishedTime}}</p>
            <p>运营人数：{{data.companyPerson}}</p>
            <p>提款限额：{{data.withdrawalLimit}}元</p>
          </div>
          <div class="right">
            <p>博彩牌照：{{data.licensePlate}}</p>
            <p>牌照编号：{{data.licenseNo}}</p>
            <p>下注限红：{{data.bottomPour}}元</p>
          </div>
        </div>
      </div>
      <div class="block bottom">
        <p class="title">游戏种类：</p>
        <div class="btn-wrap">
          <span
            v-for="(item, index) in data.gameList"
            :key="index"
          >
            {{item}}
          </span>
        </div>
        <p class="title">游戏平台：</p>
        <div class="btn-wrap">
          <span
            v-for="(item, index) in data.gamePlate"
            :key="index"
          >
            {{item}}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'EditGuaranteeBlock',
  props: {
    data: {
      type: Object,
      required: true
    },
    reverse: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    compensationAmount() {
      let amount = this.data.compensationAmount;
      let suffix = '';
      if (amount > 10000) {
        if (amount > 100000000) {
          amount = (amount / 100000000).toFixed(2);
          suffix = '亿';
        } else {
          amount = (amount / 10000).toFixed(2);
          suffix = '万';
        }
      }
      return {
        amount,
        suffix
      };
    }
  },
  methods: {
    joinGuarantee() {
      this.$message({
        message: '已加入该公司',
        type: 'success'
      });
    },
    toCompany() {
      this.$router.push({
        path: `company/${this.data.id}`
      });
    },
    newDiscount() {
      this.$router.push({
        path: 'discounts'
      });
    }
  }
};
</script>

<style lang="less" scoped>
  .block-wrap {
    display: flex;
    margin: 10px 0;
    padding: 10px;
    &.reverse {
      flex-direction: row-reverse;
      .aside {
        margin-left: 20px;
        margin-right: 0;
      }
    }
    .aside {
      display: flex;
      margin-right: 20px;
      flex-direction: column;
      flex: 0 0 240px;
      min-height: 260px;
      padding: 20px 0;
      border-radius: 8px;
      align-items: center;
      background-color: #66b9ea;
      img {
        width: 80px;
        height: 80px;
        margin: 10px 0;
      }
      .btn-group {
        display: flex;
        margin-top: 10px;
        flex: 1;
        flex-direction: column;
        justify-content: space-around;
        span {
          padding: 6px 0;
          width: 120px;
          border-radius: 5px;
          text-align: center;
          background-color: #fff;
          cursor: pointer;
          &:hover {
            opacity: .8;
          }
        }
      }
    }
    .main {
      display: flex;
      flex: 1;
      flex-direction: column;
      color: #666;
      .block {
        flex: 1;
        padding: 10px 20px;
        border-radius: 8px;
        background-color: #f5f8ff;
      }
      .top {
        display: flex;
        flex: 0 0 100px;
        .guarantee {
          display: flex;
          max-width: 360px;
          margin-right: 20px;
          padding-left: 30px;
          justify-content: center;
          background-color: #f5f8ff;
          > div {
            display: flex;
            flex: 1;
            flex-direction: column;
            justify-content: space-between;
            p {
              flex: 1;
            }
            &.limit,
            &.user {
              padding: 10px 0;
              p:last-child {
                color: #fd8723;
                span {
                  font-size: 24px;
                  font-weight: 600;
                }
              }
            }
            &.user {
              p:last-child {
                color: #ae1ff9;
              }
            }
          }
        }
        .company {
          display: flex;
          > div {
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            flex: 1;
            padding: 10px 0;
          }
        }
      }
      .bottom {
        margin-top: 10px;
        padding-left: 30px;
        .btn-wrap {
          display: flex;
          flex-wrap: wrap;
          margin: 10px 0;
          span {
            margin-right: 10px;
            padding: 5px 15px;
            border-radius: 5px;
            color: #fff;
            background-color: #769dff;
          }
        }
      }
    }
  }
</style>
